home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Complete Internet Archive
/
Complete Internet Archive.iso
/
VRML
/
cp2b2x.exe
/
DATA.Z
/
ufo.java
< prev
next >
Wrap
Text File
|
1996-06-21
|
4KB
|
166 lines
// $Id: ufo.java,v 1.5 1996/05/28 09:57:32 sugino Exp $
//
// ufo.java
//
// (c)Copyright 1996 Sony Corporation. All rights reserved.
//
import vrml.*;
public class ufo extends Script{
SFVec3f ufo_trans = (SFVec3f) getEventOut("ufoTr");
SFBool setTimerEnabled = (SFBool) getEventOut( "setTimerEnabled" );
int flg = 0;
int height = 0;
public ufo(){
}
public void clicked ( ConstSFBool ev, ConstSFTime time ){
// when the button is pressed, return immediately.
if( ev.getValue() == true ) return;
// when the button is released...
switch ( flg ){
case ( 0 ): // landing, set to rising
flg = 1;
start();
break;
case ( 2 ): // flying, set to swinging
flg = 3;
start();
break;
case ( 3 ): // swinging, set to falling
flg = 4;
break;
default:
break;
}
}
public void move ( ConstSFTime ev, ConstSFTime time ){
switch ( flg ) {
case ( 1 ):
// rising
rise();
if( height >= 20 ){
flg = 2;
stop();
}
break;
case ( 3 ):
// swinging
swing();
break;
case ( 4 ):
// go back.
if(height > 0){
gobackFall();
}else if(height < 0){
gobackRise();
}
if( height == 0 ){
flg = 0;
stop();
}
break;
default:
break;
}
}
float movepara[] = new float[3];
public void rise(){
movepara[ 1 ] += 2.0f;
ufo_trans.setValue( movepara );
height = height + 2;
}
public void gobackFall(){
movepara[ 1 ] += -1.0f;
ufo_trans.setValue( movepara );
height = height - 1;
}
public void gobackRise(){
movepara[ 1 ] += 1.0f;
ufo_trans.setValue( movepara) ;
height = height + 1;
}
public void swing(){
// random swinging.
int randomNum = (int)(6 * Math.random());
switch(randomNum){
case 0:
swingLeft();
break;
case 1:
swingRight();
break;
case 2:
swingUp();
break;
case 3:
swingDown();
break;
case 4:
swingRise();
break;
case 5:
swingFall();
break;
default:
// do nothing.
}
}
public void swingLeft(){
movepara[ 0 ] += -2.0f;
ufo_trans.setValue( movepara ) ;
}
public void swingRight(){
movepara[ 0 ] += 2.0f;
ufo_trans.setValue( movepara ) ;
}
public void swingUp(){
movepara[ 1 ] += 2.0f;
ufo_trans.setValue( movepara ) ;
height = height + 2;
}
public void swingDown(){
movepara[ 1 ] += -2.0f;
ufo_trans.setValue( movepara ) ;
height = height - 2;
}
public void swingRise(){
movepara[ 1 ] += 5.0f;
ufo_trans.setValue( movepara ) ;
height = height + 5;
}
public void swingFall(){
movepara[ 1 ] += -5.0f;
ufo_trans.setValue( movepara ) ;
height = height - 5;
}
public void start(){
System.out.println("start() enter.");
setTimerEnabled.setValue( true );
}
public void stop(){
System.out.println("stop() enter.");
setTimerEnabled.setValue( false );
}
}